<%@ include file="/html/init.jsp" %>

<c:set var="models" value="${requestScope.models}"/>
<c:set var="redirect" value="${requestScope.backURL}"/>
<c:set var="action" value="${requestScope.action}" />
<c:set var="listTables" value="${requestScope.listTables}" />

<aui:model-context bean="${models}" model="<%= models.class %>" />

<c:choose>
	<c:when test="${models == null}">
		<portlet:actionURL name="addModelWS" var="editModelWSURL" windowState="normal" />
		<aui:form action="<%= editModelWSURL %>" method="POST" name="fm">
		<aui:fieldset>
		<aui:input type="hidden" name="redirect" value="${redirect}" />
		<c:choose>
			<c:when test="${models == null} ">
				<aui:input type="hidden" name="_id" value=""/>
			</c:when>
			<c:otherwise>
				<aui:input type="hidden" name="_id" value="${models._id}"/>
			</c:otherwise>
		</c:choose>
		<c:choose>
			<c:when test="${models == null} ">
				<aui:input type="hidden" name="modelName" value=""/>
			</c:when>
			<c:otherwise>
				<aui:input type="hidden" name="modelName" value="${models.model}"/>
			</c:otherwise>
		</c:choose>
		<aui:input type="textbox" label='<%=LanguageUtil.get(pageContext, "modelWS-URL") %>' name='WSUrl' size='150'/>
		<aui:input type="textbox" label='<%=LanguageUtil.get(pageContext, "modelWS-service") %>' name='WSService' size='50'/>
		<aui:input type="textbox" label='<%=LanguageUtil.get(pageContext, "modelWS-dataType") %>' name='WSDataType' size='25'/>	
	<c:choose>
		<c:when test="${models == null}">
			<aui:input label='<%=LanguageUtil.get(pageContext, "is-active") %>' name="active" type="checkbox" checked="false"/>
		</c:when>
		<c:otherwise>
			<aui:input label='<%=LanguageUtil.get(pageContext, "is-active") %>' name="active" type="checkbox" checked="${models.active}"/>
		</c:otherwise>
	</c:choose>
	
		</aui:fieldset>
			
		<aui:button-row>
			<aui:button type="submit" value='<%=LanguageUtil.get(pageContext, "accept") %>'  />
			<aui:button type="cancel" name='<%=LanguageUtil.get(pageContext, "cancel") %>' onClick="${redirect}" />
		</aui:button-row>
		</aui:form>
	</c:when>
	<c:otherwise>
		<portlet:actionURL name="updateModel" var="editModelURL" windowState="normal" />
		<aui:form action="<%= editModelURL %>" method="POST" name="fm">
		<aui:fieldset>
		<aui:input type="hidden" name="redirect" value="${redirect}" />
		<c:choose>
			<c:when test="${models == null} ">
				<aui:input type="hidden" name="_id" value=""/>
			</c:when>
			<c:otherwise>
				<aui:input type="hidden" name="_id" value="${models._id}"/>
			</c:otherwise>
		</c:choose>
		<aui:select label='<%=LanguageUtil.get(pageContext, "model-name") %>' name='model'>
			<c:forEach items="${listTables}" var="model">
				<c:if test="${model != selected}">
					<aui:option value="${model}" label="${model}" selected="${model == models.model}"/>
				</c:if>
			</c:forEach>
		</aui:select>

		<c:choose>
			<c:when test="${models == null}">
				<aui:input label='<%=LanguageUtil.get(pageContext, "is-active") %>' name="active" type="checkbox" checked="false"/>
			</c:when>
			<c:otherwise>
				<aui:input label='<%=LanguageUtil.get(pageContext, "is-active") %>' name="active" type="checkbox" checked="${models.active}"/>
			</c:otherwise>
		</c:choose>
	
			</aui:fieldset>
			
			<aui:button-row>
				<aui:button type="submit" value='<%=LanguageUtil.get(pageContext, "accept") %>'  />
				<aui:button type="cancel" name='<%=LanguageUtil.get(pageContext, "cancel") %>' onClick="${redirect}" />
			</aui:button-row>
		</aui:form>
	</c:otherwise>
</c:choose>